<?php /** @var $this \Action\Index */

use Action\Page\Del;
use Action\Page\Edit;
use Action\Page\View; ?>
<?php $this->outputHeader() ?>
    
    <link rel="stylesheet" href="/static/css/index.css">

<div class="list-files-head">
    <div class="button-bar">
        <a class="button" href="/?a=page.edit">+ 添加新页面</a>
    </div>
    <!-- 表格头 -->
    <div class="list-item">
        <!--cur 筛选条件高亮-->
        <div class="list-item-label list-item-label-title sort-title">
            <span class="list-item-text">ID</span>
        </div>
        <div class="list-item-label list-item-label-title sort-title" href="<?= $this->getSortUrl('name') ?>">
            <span class="list-item-text">名称</span>
        </div>
        <div class="list-item-label list-item-label-title sort-title">
            <span class="list-item-text">网页标题</span>
        </div>
        <div class="list-item-label list-item-label-template sort-title">
            <span class="list-item-text">模板</span>
        </div>
        <div class="list-item-label list-item-label-time sort-title" href="<?= $this->getSortUrl('time') ?>">
            <span class="list-item-text">上次修改时间</span>
        </div>
        <div class="list-item-label list-item-label-action">
            <span class="list-item-text">操作</span>
        </div>
    </div>
</div>
<div class="list-files-body">
    <ul class="list">
        <?php //var_dump($this->getPageList()); ?>
        <?php if(empty($this->getPageList())): ?>
            <li class="list-item empty">还没有页面</li>
        <?php else: ?>
            <?php foreach ($this->getPageList() as $item): ?>
                <li class="list-item <?php echo $item['enabled'] ? '' : 'disabled' ?>">
                    <div class="list-item-label list-item-label-title">
                        <span class="list-item-text">
                                <?= $item['id'] ?>
                        </span>
                    </div>
                    <div class="list-item-label list-item-label-title">
                        <span class="list-item-text">
                                <?= $item['name'] ?>
                        </span>
                    </div>
                    <div class="list-item-label list-item-label-title">
                        <span class="list-item-text">
                                <?= $item['data']['title'] ?>
                        </span>
                    </div>
                    <div class="list-item-label list-item-label-template">
                        <span class="list-item-text">
                                <?= $this->pageModel->getTemplateVal($item['template'], 'name') ?>
                        </span>
                    </div>
                    <div class="list-item-label list-item-label-time">
                        <span class="list-item-text"><?= $item['last_updated_at'] ? date('Y-m-d H:i:s', $item['last_updated_at']) : "" ?></span>
                    </div>
                    <div class="list-item-label list-item-label-action">
                        <?php if(!$item['is_dir']): ?>
                            <div class="action action-ground">
                                <a class="action-text" href="<?php echo Edit::getActionUrl(['id'=>$item['id']]) ?>">编辑</a>
                                <a class="action-text delete" onclick="return confirm('确定删除吗?')" href="<?php echo Del::getActionUrl(['id' => $item['id']]) ?>">删除</a>
                                <div class="action-more">
                                    <i class="icon icon-arrow-solid"></i>
                                    <ul class="menu-dropdown">
                                        <li class="menu-dropdown-item">
                                            <a class="menu-dropdown-label" target="_blank" href="<?php echo View::getActionUrl(['id' => $item['id'], 'preview' => 1]) ?>">预览</a>
                                        </li>
                                        <li class="menu-dropdown-item">
                                            <a class="menu-dropdown-label" target="_blank" href="/page/<?php echo $item['id'] ?>">查看</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                            
                        <?php endif; ?>
                    </div>
                </li>
            <?php endforeach; ?>
        <?php endif; ?>
    </ul>
</div>
<div class="list-files-footer">
    <span>共 <?= count($this->getPageList()) ?> 个项目 
</div>

<?php $this->outputFooter() ?>